<?php
ini_set("display_errors", true);
error_reporting(E_ALL);

require_once('../simpletest/autorun.php');
require_once('../../src/v1/scottlib-test.php');

class TestBuilderSimpleDB extends UnitTestCase {
	
	function testEq() {
		eval(all_criteria());
		
		$builder = new slSimpleDBCriteriaBuilder('default', $eq('color', 'red'));
		
		$this->assertEqual("SELECT itemName() FROM default WHERE ( color = 'red' )", $builder->build());
	}
	
	function testNe() {
		eval(all_criteria());
		
		$builder = new slSimpleDBCriteriaBuilder('default', $ne('color', 'red'));
		
		$this->assertEqual("SELECT itemName() FROM default WHERE ( color != 'red' )", $builder->build());
	}
	
	function testAnd() {
		eval(all_criteria());
		
		$builder = new slSimpleDBCriteriaBuilder('default', $and(
			$eq('color', 'red'),
			$eq('color', 'blue')
		));
		
		$this->assertEqual("SELECT itemName() FROM default WHERE ( color = 'red' ) AND ( color = 'blue')", $builder->build());
	}
	
	function testEach() {
		eval(all_criteria());
		
		$builder = new slSimpleDBCriteriaBuilder('default', $each(array('one', 'two', 'three'), 'num', $eq('num', ':num')));
		
		$this->assertEqual("SELECT itemName() FROM default WHERE ( num = 'one' ) AND ( num = 'two' ) AND ( num = 'three' )", $builder->build());
	}
}